﻿using AiFrame.Base.Core;
using AiFrame.Base.Core.Plugins;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using AiFrame.InterfaceLib.MVP;
using AiFrame.InterfaceLib.Windows.Themes;
using AiFrame.InterfaceLib.Windows.UI;
using AiFrame.InterfaceLib.Data.Access;
using AiFrame.InterfaceLib.Plugins;
using AiFrame.InterfaceLib.Data.Provider;
using Moq;

namespace Base.Core.Tests
{
    
    
    /// <summary>
    ///Dies ist eine Testklasse für "CoreInterfaceTest" und soll
    ///alle CoreInterfaceTest Komponententests enthalten.
    ///</summary>
    [TestClass()]
    public class CoreInterfaceTest
    {
        
        private TestContext testContextInstance;

        /// <summary>
        ///Ruft den Testkontext auf, der Informationen
        ///über und Funktionalität für den aktuellen Testlauf bietet, oder legt diesen fest.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Zusätzliche Testattribute
        // 
        //Sie können beim Verfassen Ihrer Tests die folgenden zusätzlichen Attribute verwenden:
        //
        //Mit ClassInitialize führen Sie Code aus, bevor Sie den ersten Test in der Klasse ausführen.
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            
        }
        //
        //Mit ClassCleanup führen Sie Code aus, nachdem alle Tests in einer Klasse ausgeführt wurden.
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Mit TestInitialize können Sie vor jedem einzelnen Test Code ausführen.
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Mit TestCleanup können Sie nach jedem einzelnen Test Code ausführen.
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Ein Test für "CoreInterface-Konstruktor"
        ///</summary>
        [TestMethod()]
        public void CoreInterfaceConstructorTest()
        {
            var windowManagerMock = new Mock<IWindowManager<IWindow>>();
            var navigationBarMock = new Mock<INavigationBar>();
            var styleGuidUIMock = new Mock<IStyleGuideUI>();
            var themeMock = new Mock<ITheme>();
            var toolbarManagerMock = new Mock<IToolBarManager>();
            var mainMenuMock = new Mock<IMainMenu>();
            CoreInterface target = new CoreInterface(windowManagerMock.Object, navigationBarMock.Object,
                styleGuidUIMock.Object, themeMock.Object, toolbarManagerMock.Object,
                mainMenuMock.Object);

            Assert.AreEqual(windowManagerMock.Object, target.WindowManager);
            Assert.AreEqual(navigationBarMock.Object, target.NavigationBar);
            Assert.AreEqual(styleGuidUIMock.Object, target.StyleGuideUI);
            Assert.AreEqual(themeMock.Object, target.Theme);
            Assert.AreEqual(toolbarManagerMock.Object, target.ToolBarManager);
            Assert.AreEqual(mainMenuMock.Object, target.MainMenu);
        }

        /// <summary>
        ///Ein Test für "DatabaseConnection"
        ///</summary>
        [TestMethod()]
        public void DatabaseConnectionTest()
        {
            var windowManagerMock = new Mock<IWindowManager<IWindow>>();
            var navigationBarMock = new Mock<INavigationBar>();
            var styleGuidUIMock = new Mock<IStyleGuideUI>();
            var themeMock = new Mock<ITheme>();
            var toolbarManagerMock = new Mock<IToolBarManager>();
            var mainMenuMock = new Mock<IMainMenu>();

            var componentFacMock = new Mock<IComponentFactory>();
            var dbMock = new Mock<IDatabaseConnection>();
            componentFacMock.Setup(c => c.DatabaseConnection).Returns(dbMock.Object);
            Factories.ComponentFactory = componentFacMock.Object;

            CoreInterface target = new CoreInterface(windowManagerMock.Object, navigationBarMock.Object,
                styleGuidUIMock.Object, themeMock.Object, toolbarManagerMock.Object,
                mainMenuMock.Object);

            Assert.AreEqual(dbMock.Object, target.DatabaseConnection);

        }

        /// <summary>
        ///Ein Test für "FactoryManager"
        ///</summary>
        [TestMethod()]
        public void FactoryManagerTest()
        {
            var windowManagerMock = new Mock<IWindowManager<IWindow>>();
            var navigationBarMock = new Mock<INavigationBar>();
            var styleGuidUIMock = new Mock<IStyleGuideUI>();
            var themeMock = new Mock<ITheme>();
            var toolbarManagerMock = new Mock<IToolBarManager>();
            var mainMenuMock = new Mock<IMainMenu>();

            var componentFacMock = new Mock<IComponentFactory>();
            var factoryManagerMock = new Mock<IFactoryManager>();
            componentFacMock.Setup(c => c.FactoryManager).Returns(factoryManagerMock.Object);
            Factories.ComponentFactory = componentFacMock.Object;

            CoreInterface target = new CoreInterface(windowManagerMock.Object, navigationBarMock.Object,
                styleGuidUIMock.Object, themeMock.Object, toolbarManagerMock.Object,
                mainMenuMock.Object);

            Assert.AreEqual(factoryManagerMock.Object, target.FactoryManager);
        }
        
        /// <summary>
        ///Ein Test für "PluginManager"
        ///</summary>
        [TestMethod()]
        public void PluginManagerTest()
        {
            var windowManagerMock = new Mock<IWindowManager<IWindow>>();
            var navigationBarMock = new Mock<INavigationBar>();
            var styleGuidUIMock = new Mock<IStyleGuideUI>();
            var themeMock = new Mock<ITheme>();
            var toolbarManagerMock = new Mock<IToolBarManager>();
            var mainMenuMock = new Mock<IMainMenu>();

            var componentFacMock = new Mock<IComponentFactory>();
            var pluginManagerMock = new Mock<IPluginManager>();
            componentFacMock.Setup(c => c.PluginManager).Returns(pluginManagerMock.Object);
            Factories.ComponentFactory = componentFacMock.Object;

            CoreInterface target = new CoreInterface(windowManagerMock.Object, navigationBarMock.Object,
                styleGuidUIMock.Object, themeMock.Object, toolbarManagerMock.Object,
                mainMenuMock.Object);

            Assert.AreEqual(pluginManagerMock.Object, target.PluginManager);
        }

        /// <summary>
        ///Ein Test für "ProviderRegistration"
        ///</summary>
        [TestMethod()]
        public void ProviderRegistrationTest()
        {
            var windowManagerMock = new Mock<IWindowManager<IWindow>>();
            var navigationBarMock = new Mock<INavigationBar>();
            var styleGuidUIMock = new Mock<IStyleGuideUI>();
            var themeMock = new Mock<ITheme>();
            var toolbarManagerMock = new Mock<IToolBarManager>();
            var mainMenuMock = new Mock<IMainMenu>();

            var componentFacMock = new Mock<IComponentFactory>();
            var providerRegMock = new Mock<IDbProviderRegistration>();
            componentFacMock.Setup(c => c.DbProviderRegistration).Returns(providerRegMock.Object);
            Factories.ComponentFactory = componentFacMock.Object;

            CoreInterface target = new CoreInterface(windowManagerMock.Object, navigationBarMock.Object,
                styleGuidUIMock.Object, themeMock.Object, toolbarManagerMock.Object,
                mainMenuMock.Object);

            Assert.AreEqual(providerRegMock.Object, target.ProviderRegistration);
        }

      
    }
}
